import { defineStore } from 'pinia'
import request from '@/utils/request.js'

export const useArchieveStore = defineStore('archieve', {
state: () => {
    return {
        archieves: [], // 所有的数据
        archievePage: {}, // 分页的数据
    };
},
 getters: {
    sorted: (state) => {
        return state.archievePage.list.sort((a, b) => new Date(b.date) - new Date(a.date));
    },
    sortedAll: (state) => {
        return state.archieves.sort((a, b) => new Date(b.date) - new Date(a.date));
    },
 },
 actions: {
    async archievePages(currentPage, size) {
        try {
          let params = {
            currentPage,
            size
          }
          let res = await request.post('/archieve/pages', params)
          this.archievePage = res.data.data;
          this.archieves.push(...this.archievePage.list);
          return res.data.data;
        } catch (error) {
          console.error(error);
        }
    }
 },
})

